home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Programming / Source / tess / tess-1.0 / aGroup.pswm < prev    next >
Encoding:
Text File  |  1992-06-30  |  6.7 KB  |  326 lines

  1. #import "aGroup.h"
  2. #import "aGroup-inter.h"
  3. #import "TessSketch.h"
  4. #import "Underlay.h"
  5. #import "GeneratorOverlay.h"
  6. #import <math.h>
  7.  
  8. @implementation aGroup
  9. +new 
  10. {
  11.   self = [super new];
  12.   [self setAutosizing: NX_WIDTHSIZABLE | NX_HEIGHTSIZABLE];
  13.   return self;
  14. }
  15.  
  16. + setup
  17. {
  18.   GroupSetup();                    // call only once
  19.   return self;
  20. }
  21.  
  22. - setupControls
  23. {
  24.   anglewin = [[superview superview] awin];
  25.   [anglewin close];
  26.   angle1slide = [[superview superview] a1slide] ;
  27.   angle2slide = [[superview superview] a2slide] ;
  28.   angle1box = [[superview superview] a1box] ;
  29.   angle2box = [[superview superview] a2box] ;
  30.   return self;
  31. }
  32.  
  33. - drawSelf:(const NXRect *)rects :(int)rectCount
  34. {
  35.   NXRect superframe;
  36.   NXPoint offset;
  37.   offset.x = offset.y = - GENOFFT;
  38.   [genovly getFrame: &superframe];
  39.   [self clip: 0 : 0 ];
  40.   [[genovly getImage]  composite: NX_COPY fromRect: &superframe toPoint: &offset];
  41.   return self;
  42. }
  43.  
  44. - setGenovly: sender
  45. {
  46.   genovly = sender;
  47.   return self;
  48. }
  49.  
  50. - defaultConfig
  51. {
  52.   return self;
  53. }
  54.  
  55. - sizeTo: (float) x : (float) y
  56. {
  57.   [super sizeTo: x : y];
  58.   [self resizeGenerator];
  59.   return self;
  60. }
  61.  
  62. - resizeGenerator
  63. {
  64.   return self;
  65. }
  66.  
  67. - anglesDidChange
  68. {
  69.   [self resizeGenerator];
  70.   [superview erase];
  71.   [superview display];
  72.   return self;
  73. }
  74.     
  75. - performTesselation: sender
  76. {
  77.   id imgview,outview,outimg;
  78.   NXPoint pt,genofft;
  79.   NXSize lsize;
  80.   NXRect outrect;
  81.   float xstart;
  82.   
  83.   outview = [sender getOutputView];
  84.   outimg = [outview getImage];
  85.   [self getLatticeUnitSize: &lsize];
  86.   [sender getImageView:&imgview withOffset: &genofft];
  87.   if(![outimg lockFocus]) fprintf(stderr,"Couldn't lock outimg focus\n");
  88.   PSgsave();
  89.   [outview getFrame: &outrect];
  90.   pt.x = pt.y = 0.0;
  91.   while (pt.y < outrect.size.height + lsize.height){
  92.     PSmoveto(0.0,0.0);
  93.     while(pt.x > -lsize.width)  
  94.       [self leftTranslatePoint: &pt];
  95.     xstart = pt.x;
  96.     while (pt.x < outrect.size.width + 2*lsize.width) {
  97.       PSgsave();
  98.       PStranslate(pt.x,pt.y);
  99.       [self makeLatticeUnitAt: &genofft fromImage: [imgview getImage]];
  100.       PSgrestore();
  101.       [self rightTranslatePoint: &pt];
  102.     } 
  103.     pt.x = xstart;
  104.     [self upTranslatePoint: &pt];
  105.   }
  106.   PSgrestore();
  107.   [outimg unlockFocus];
  108.   return self;
  109. }
  110.  
  111. - generator: (NXCoord) x : (NXCoord) y
  112. {
  113.   [self clip: x : y];
  114.   PSstroke();
  115.   return self;
  116. }
  117. - clip: (NXCoord) x: (NXCoord) y {  return self; }
  118. - (BOOL) isRigidLattice {  return YES; }
  119. - rightTranslatePoint: (NXPoint *) pt { return self; }
  120. - leftTranslatePoint: (NXPoint *) pt { return self; }
  121. - upTranslatePoint: (NXPoint *)pt {  return self; }
  122. - (NXSize *)getLatticeUnitSize: (NXSize *) size
  123. {
  124.   size->width = latticesize.width;
  125.   size->height = latticesize.height;
  126.   return &latticesize;
  127. }
  128. - drawImage
  129. {
  130.   [self sketchTemplate];
  131.   return self;
  132. }
  133. - sketchTemplate
  134. {
  135.   return self;
  136. }
  137. - makeLatticeUnitAt: (NXPoint *) point fromImage: srcimg {  return self; }
  138. - (NXPoint *)getGeneratorOffset: (NXPoint *) pt
  139. {
  140.   pt->x = pt->y = 0.0;
  141.   return pt;
  142. }
  143.  
  144. - (NXSize *)getGeneratorSize: (NXSize *) size
  145. {
  146.   return &frame.size;
  147. }
  148.  
  149. - singleAngleSetup: (float) a
  150. {
  151.   [anglewin makeKeyAndOrderFront: self];
  152.   [angle1slide setEnabled: YES];
  153.   [angle1slide setFloatValue: a];
  154.   [angle2slide setEnabled: NO];
  155.   [anglewin update];
  156.   return self;
  157. }
  158.  
  159. - twoAngleSetup: (float) a : (float) b
  160. {
  161.   [anglewin makeKeyAndOrderFront: self];
  162.   [angle1slide setEnabled: YES];
  163.   [angle1slide setFloatValue: a];
  164.   [angle2slide setEnabled: YES];
  165.   [angle2slide setFloatValue: b];
  166.   [anglewin update];
  167.   return self;
  168. }
  169.  
  170. - noAngleSetup
  171. {
  172.   [anglewin close];
  173.   return self;
  174. }
  175.  
  176. - setAngle1: (float) a1
  177. {
  178.   [angle1slide setFloatValue: a1];
  179.   [self anglesDidChange];
  180.   return self;
  181. }
  182. - setAngle2: (float)  a2
  183. {
  184.   [angle2slide setFloatValue: a2];
  185.   [self anglesDidChange];
  186.   return self;
  187. }
  188. - sizeKludge: (float *) x : (float *) y
  189. {
  190.   *x = *y;
  191.   return self;
  192. }
  193. @end
  194.  
  195. int genfun () {  return 1; }
  196. int clipper () { return 1; }
  197. int tesselate () { return 1;}
  198.  
  199. defineps GroupSetup()
  200.    /groupsdict 40 dict def
  201.    groupsdict begin
  202.        /equi { 3 sqrt mul 2 div } bind def
  203.        /generatorcolor {0.655171 0.102771 0.629475 setrgbcolor } bind def
  204.        /glidecolor {0.373226 0.462386 0.528733 setrgbcolor } bind def
  205.        /reflectioncolor {0.333338 0.039216 0.237907 setrgbcolor } bind def
  206.        /translationcolor {1 0.054903 0.101962 setrgbcolor       } bind def
  207.        /anglecolor { 0 0 1 setrgbcolor } bind def
  208.        /latticeunitcolor { 0.5 setgray } bind def
  209.        /scaling 1.0 def    
  210.  
  211.        /arrow { % angle x y
  212.        newpath moveto dup rotate 
  213.        -13 6 rlineto 4 -6 rlineto 
  214.        -4 -6 rlineto closepath gsave 0 
  215.        setlinejoin stroke grestore fill neg rotate
  216.        } def
  217.  
  218.        /addpoints { % x y x y
  219.           exch % x y y x
  220.           4 1 roll %  y y x x
  221.           add 3 1 roll % x y y
  222.           add % x y
  223.     } bind def
  224.  
  225.        /duptop2 { % x y -> x y x y
  226.        dup     %  x y y
  227.        3 2 roll % y y x
  228.        dup % y y x x    
  229.        4 1 roll % x y y x
  230.        exch % x y x y    
  231.        } bind def
  232.  
  233.        /even { % num
  234.        cvi 1 and 1 eq not
  235.        } bind def
  236.  
  237.        /setscaling { % scale - wrap with dictionary use !!!
  238. %       groupsdict begin       
  239. %           /scaling exch def    
  240. %           [scaling 0 0 scaling 0 0] setmatrix
  241. %       end           
  242.     pop
  243.        } bind def
  244.  
  245.        /reflect { % angle
  246.        dup rotate  
  247.        [1 0 0 -1 0 0] concat 
  248.        neg rotate     
  249.        }     bind def
  250.  
  251.        /rhombus { % x y 
  252.        groupsdict begin    
  253.            moveto
  254.            latticeunitcolor
  255.            lattice:side 0 lineto
  256.            lattice:w lattice:h rlineto
  257.            lattice:side neg 0 rlineto
  258.            closepath
  259.            stroke
  260.        end        
  261.        } bind def
  262.  
  263.        /transv0 { %x y len
  264.        groupsdict begin
  265.            gsave    
  266.            2 setlinewidth
  267.            translationcolor    
  268.            moveto dup 0 rlineto stroke    
  269.            0 exch 0 arrow
  270.            grestore    
  271.        end        
  272.        } bind def
  273.  
  274.        /transv90 { %x y len
  275.        groupsdict begin
  276.            gsave 
  277.            2 setlinewidth
  278.            translationcolor    
  279.            moveto dup 0 exch rlineto stroke    
  280.            90 exch 0 exch arrow
  281.            grestore    
  282.        } bind def
  283.  
  284.        /transv60 { %x y run rise
  285.        groupsdict begin
  286.            gsave 
  287.            2 setlinewidth
  288.            translationcolor    
  289.            moveto 
  290.            duptop2    
  291.            rlineto stroke    
  292.            60 3 1 roll % angle of arrow
  293.            arrow
  294.            grestore    
  295.        end        
  296.        } bind def
  297.  
  298.        /reflectionaxis { % x1 y1 x2 y2
  299.        groupsdict begin    
  300.            reflectioncolor
  301.            moveto rlineto stroke    
  302.        end
  303.        } bind def
  304.  
  305.        /rotation3 { % size x y
  306.        groupsdict begin    
  307.            moveto    
  308.            /r3size exch def
  309.            /r3ext r3size equi def    
  310.            anglecolor
  311.            0 r3ext 2 div rmoveto
  312.            r3size 2 div r3ext neg rlineto
  313.            r3size neg 0 rlineto
  314.            closepath 
  315.            gsave fill grestore stroke
  316.        end
  317.        } bind def
  318.    end
  319. endps
  320.  
  321. defineps reflect(float angle)
  322.      groupsdict begin
  323.          angle reflect
  324.      end 
  325. endps
  326.